/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ylystudio.pms.ejb.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Kenny Lin
 */
@Entity
@Table(name = "error_middle")
@NamedQueries({
    @NamedQuery(name = "ErrorMiddle.findAll", query = "SELECT e FROM ErrorMiddle e"),
    @NamedQuery(name = "ErrorMiddle.findByErrorNumber", query = "SELECT e FROM ErrorMiddle e WHERE e.errorNumber = :errorNumber"),
    @NamedQuery(name = "ErrorMiddle.findByGradeId", query = "SELECT e FROM ErrorMiddle e WHERE e.errorMiddlePK.gradeId = :gradeId"),
    @NamedQuery(name = "ErrorMiddle.findByErrorId", query = "SELECT e FROM ErrorMiddle e WHERE e.errorMiddlePK.errorId = :errorId")})
public class ErrorMiddle implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ErrorMiddlePK errorMiddlePK;
    @Basic(optional = false)
    @Column(name = "error_number")
    private long errorNumber;
    @JoinColumn(name = "grade_id", referencedColumnName = "grade_id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Grade grade;
    @JoinColumn(name = "error_id", referencedColumnName = "error_id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private ErrorType errorType;

    public ErrorMiddle() {
    }

    public ErrorMiddle(ErrorMiddlePK errorMiddlePK) {
        this.errorMiddlePK = errorMiddlePK;
    }

    public ErrorMiddle(ErrorMiddlePK errorMiddlePK, long errorNumber) {
        this.errorMiddlePK = errorMiddlePK;
        this.errorNumber = errorNumber;
    }

    public ErrorMiddle(int gradeId, int errorId) {
        this.errorMiddlePK = new ErrorMiddlePK(gradeId, errorId);
    }

    public ErrorMiddlePK getErrorMiddlePK() {
        return errorMiddlePK;
    }

    public void setErrorMiddlePK(ErrorMiddlePK errorMiddlePK) {
        this.errorMiddlePK = errorMiddlePK;
    }

    public long getErrorNumber() {
        return errorNumber;
    }

    public void setErrorNumber(long errorNumber) {
        this.errorNumber = errorNumber;
    }

    public Grade getGrade() {
        return grade;
    }

    public void setGrade(Grade grade) {
        this.grade = grade;
    }

    public ErrorType getErrorType() {
        return errorType;
    }

    public void setErrorType(ErrorType errorType) {
        this.errorType = errorType;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (errorMiddlePK != null ? errorMiddlePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ErrorMiddle)) {
            return false;
        }
        ErrorMiddle other = (ErrorMiddle) object;
        if ((this.errorMiddlePK == null && other.errorMiddlePK != null) || (this.errorMiddlePK != null && !this.errorMiddlePK.equals(other.errorMiddlePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ylystudio.pms.ejb.entity.ErrorMiddle[errorMiddlePK=" + errorMiddlePK + "]";
    }

}
